package com.miniapp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.miniapp.entity.MiniTemplateEntity;
import com.miniapp.entity.MiniTesterEntity;
import com.miniapp.mapper.MiniTemplateMapper;
import com.miniapp.mapper.MiniTesterMapper;
import com.miniapp.service.MiniTesterService;
import com.miniapp.utils.BaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class MiniTesterServiceImpl  extends BaseServiceImpl<MiniTesterMapper,MiniTesterEntity>  implements MiniTesterService {


    @Override
    public MiniTesterEntity findByMiniUserProductIdAndWechatId(Long id, String wechatId) {
        return baseMapper.selectOne(new QueryWrapper<MiniTesterEntity>().eq("user_product_id",id).eq("wechat_id",wechatId));
    }

    @Override
    public void saveTester(String wechatId, Long id) {
        MiniTesterEntity miniTester = new MiniTesterEntity();
        miniTester.setUserProductId(id);
        miniTester.setWechatId(wechatId);
        baseMapper.insert(miniTester);
    }

    @Override
    public void deleteTester(Long id, String wechatId) {
       MiniTesterEntity miniTester = this.findByMiniUserProductIdAndWechatId(id,wechatId);
        if (BaseUtils.isNotEmpty(miniTester)){
            baseMapper.deleteById(miniTester.getId());
        }
    }

    @Override
    public List<MiniTesterEntity> findByMiniUserProductId(Long id) {
        return baseMapper.selectList(new QueryWrapper<MiniTesterEntity>().eq("user_product_id",id));
    }
}
